package kz.edu.sdu.atm.models;

import java.io.PrintWriter;
import java.math.BigDecimal;

import kz.edu.sdu.atm.util.Logger;

public class UserFDTO extends UserDTO{
	protected Logger log = new Logger(UserFDTO.class);
	
	public UserFDTO(){
		super();
	}
	
	public UserFDTO(UserDTO u){
		super();
		setUsername(u.getUsername());
		setPassword(u.getPassword());
		setMoney(u.getMoney());
	}
	
	public boolean init(String line){
		String [] v = line.split(";");
		if (v.length != 3){
			log.error(String.format("Invalid line: %s", line));
			return false;
		}
		setUsername(v[0]);
		setPassword(v[1]);
		setMoney(new BigDecimal(v[2]));
		return true;
	}
	
	public void save(PrintWriter out){
		out.println(toSaveString());
	}
	
	public String toSaveString(){
		return String.format("%s;%s;%f;", getUsername(), getPassword(), getMoney());
	}
	
	public String toString(){
		return toSaveString();
	}

}
